package com.example.mybatisplusgen.utils.response;


/**
 * @author 李卓轩
 */
public class CommonResponse<T>{
    private Boolean success;
    private int code;
    private String message;
    private T data;
    private Integer current;
    private Integer size;
    private Long total;

    public Integer getCurrent() {
        return current;
    }

    public void setCurrent(Integer current) {
        this.current = current;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public CommonResponse(Boolean success, Code resultCode, T data, Integer current, Integer size, Long total) {
        this.success = success;
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
        this.data = data;
        this.current = current;
        this.size = size;
        this.total = total;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public CommonResponse(){

    }





    public CommonResponse (Code resultCode, Boolean success , T data){
        this.success = success;
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
        this.data = data;
    }

    public CommonResponse err(int code, String message){
        this.code = code;
        this.message = message;
        this.success = false;
        return this;
    }
    public static<T> CommonResponse Ipage(T data, boolean success, Integer current, Integer size, Long total){
        return new CommonResponse<>(success,Code.HTTP_SUCCESS, data, current, size, total);
    }

    public static<T> CommonResponse<T> ok(T data){
        return new CommonResponse<>(Code.HTTP_SUCCESS, true , data);
    }

    public static CommonResponse fail(){
        return new CommonResponse<>(Code.HTTP_FAIL, false, null);
    }

    public static CommonResponse fail(int code , String message){
        return new CommonResponse<>().err(code, message);
    }




}
